#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
struct ListNode {
    int val;
    ListNode* next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};
ListNode* swapPairs(ListNode* head) {
    if (!head)
        return nullptr;
    if (!head->next)
        return head;
    ListNode* cur = head;
    head = head->next;
    ListNode* next = cur->next;
    cur->next = next->next;
    next->next = cur;
    ListNode* prev = cur;
    cur = prev->next;
    next = cur->next;
    while (1) {
        if (cur->next == nullptr)
            return head;
        prev->next = next;
        cur->next = next->next;
        next->next = cur;
        if (cur->next == nullptr || cur->next->next == nullptr)
            return head;
        next = cur->next->next;
        cur = prev->next->next->next;
        prev = prev->next->next;
    }
}
int main()
{
    ListNode head1, head2, head3, head4;
    head1.val = 1;
    head2.val = 2;
    //head3.val = 3;
    //head4.val = 4;
    head1.next = &head2;
    //head2.next = &head3;
    //head3.next = &head4;
    swapPairs(&head1);
}
